//
//  RNOLHomeIndexView.m
//  RongNiuOnline
//
//  Created by apple on 2018/4/8.
//  Copyright © 2018年 rongniu. All rights reserved.
//

#import "RNOLHomeIndexView.h"
#import "RNOLGirdView.h"


@interface RNOLHomeIndexView()

@property (nonatomic,strong) NSArray *titles;
@property (nonatomic,strong) NSArray *images;
@property (nonatomic,copy) void(^indexClickBlock) (NSInteger index);

@end


@implementation RNOLHomeIndexView


- (instancetype)initWithFrame:(CGRect)frame Titles:(NSArray *)titlesArray
                    images:(NSArray *)images
                  callBack:(void(^)(NSInteger index))callBack{
//    if (frame.size.height < 100 ) {
//        frame.size.height = 100 ;
//    }
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = KWhiteColor;
        self.images = images;
        self.titles = titlesArray;
        self.indexClickBlock = callBack;
        [self setup];
    }
    return self;
    
}

- (void)setup{
    NSArray *titles = self.titles;
    NSArray *images = self.images;
//  @[@"产品介绍",@"平台数据",@"安全保障",@"新手指引"];
//    @[@"rnol_home_icon001",@"rnol_home_icon002",@"rnol_home_icon003",@"rnol_home_icon004"];
    CGFloat margin = 5;
    CGFloat space = 15 ;
    NSInteger count = titles.count;
    CGFloat girdY = 0;
    CGFloat girdW = (KWIDTH - space*2 - (count-1) * margin )/titles.count;
    CGFloat girdH = self.height;

    for (NSInteger i = 0; i < titles.count; i++) {
        RNOLGirdView *girdView = [RNOLGirdView FromXIB];
        girdView.frame = CGRectMake(space + (girdW+margin)*i, girdY, girdW , girdH);
        girdView.titleLabel.font = kFont(15);
        girdView.titleLabel.textColor = kTextColor;
        girdView.titleLabel.text = titles[i];
        girdView.iconView.image = [UIImage imageNamed: images[i]];
        girdView.coverButton.tag = i ;
        [girdView.coverButton addButtonActionClickHandler:^(NSInteger tagIndex) {
            !self.indexClickBlock? : self.indexClickBlock(tagIndex);
        }];
        [self addSubview: girdView];
    }
}



@end
